﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OracleClient;
using DBUtility;
namespace OracleDAL.Room
{
    /// <summary>
    /// 数据访问类ROOM_EQUIPMENTLAYOUT。
    /// </summary>
    public class ROOM_EQUIPMENTLAYOUT
    {
        public ROOM_EQUIPMENTLAYOUT()
        { }
        #region  成员方法

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string LOGICEQUIPMENTID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from ROOM_EQUIPMENTLAYOUT");
            strSql.Append(" where LOGICEQUIPMENTID=:LOGICEQUIPMENTID ");
            OracleParameter[] parameters = {
					new OracleParameter(":LOGICEQUIPMENTID", OracleType.VarChar,50)};
            parameters[0].Value = LOGICEQUIPMENTID;

            return OracleHelper.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(Model.Room.ROOM_EQUIPMENTLAYOUT model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into ROOM_EQUIPMENTLAYOUT(");
            strSql.Append("LOGICEQUIPMENTID,LOGICEQUIPMENTNAME,EQUIPMENTPROPERTY,TOP,LEFT,REMARK,TXTCONTENT,TXTPROPERTY,TYPE)");
            strSql.Append(" values (");
            strSql.Append(":LOGICEQUIPMENTID,:LOGICEQUIPMENTNAME,:EQUIPMENTPROPERTY,:TOP,:LEFT,:REMARK,:TXTCONTENT,:TXTPROPERTY,:TYPE)");
            OracleParameter[] parameters = {
					new OracleParameter(":LOGICEQUIPMENTID", OracleType.VarChar,25),
					new OracleParameter(":LOGICEQUIPMENTNAME", OracleType.VarChar,100),
					new OracleParameter(":EQUIPMENTPROPERTY", OracleType.VarChar,1000),
					new OracleParameter(":TOP", OracleType.Number,4),
					new OracleParameter(":LEFT", OracleType.Number,4),
					new OracleParameter(":REMARK", OracleType.VarChar,500),
					new OracleParameter(":TXTCONTENT", OracleType.VarChar,25),
					new OracleParameter(":TXTPROPERTY", OracleType.VarChar,1000),
					new OracleParameter(":TYPE", OracleType.VarChar,20)};
            parameters[0].Value = model.LOGICEQUIPMENTID;
            parameters[1].Value = model.LOGICEQUIPMENTNAME;
            parameters[2].Value = model.EQUIPMENTPROPERTY;
            parameters[3].Value = model.TOP;
            parameters[4].Value = model.LEFT;
            parameters[5].Value = model.REMARK;
            parameters[6].Value = model.TXTCONTENT;
            parameters[7].Value = model.TXTPROPERTY;
            parameters[8].Value = model.TYPE;

            OracleHelper.ExecuteSql(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 增加一条数据(调用存储过程)
        /// </summary>
        /// <param name="ID">ID(根据类型有不同的含义，)</param>
        /// <param name="EQUIPMENTTYPE">设备类型</param>
        /// <param name="PCLASS">分类(ROOM 机房，SERVICECONNECTION 服务连接图)</param>
        /// <param name="model">设备布局Model</param>
        public void Add(string ID, string EQUIPMENTTYPE, string PCLASS, Model.Room.ROOM_EQUIPMENT model)
        {
            OracleParameter[] parameters = {
					new OracleParameter("p_id", OracleType.VarChar,25),
					new OracleParameter("p_logicequipmentname", OracleType.VarChar,100),
					new OracleParameter("p_equipmentproperty", OracleType.VarChar,1000),
					new OracleParameter("p_top", OracleType.Int32),
					new OracleParameter("p_left", OracleType.Int32),
					new OracleParameter("p_remark",  OracleType.VarChar,500),
					new OracleParameter("p_txtcontent",  OracleType.VarChar,25),
					new OracleParameter("p_txtproperty",  OracleType.VarChar,1000),
					new OracleParameter("p_type", OracleType.VarChar,20),
                    new OracleParameter("p_equipmentid", OracleType.VarChar,25),
					new OracleParameter("p_equipmenttype", OracleType.VarChar,25),
					new OracleParameter("p_class", OracleType.VarChar,20)};
            parameters[0].Value = ID;
            parameters[1].Value = model.LOGICEQUIPMENTNAME;
            parameters[2].Value = model.EQUIPMENTPROPERTY;
            parameters[3].Value = Convert.ToInt32(model.TOP);
            parameters[4].Value = Convert.ToInt32(model.LEFT);
            parameters[5].Value = model.REMARK;
            parameters[6].Value = model.TXTCONTENT;
            parameters[7].Value = model.TXTPROPERTY;
            parameters[8].Value = model.TYPE;
            parameters[9].Value = model.EQUIPMENTID;
            parameters[10].Value = EQUIPMENTTYPE;
            parameters[11].Value = PCLASS;

            parameters[0].Direction = ParameterDirection.Input;
            parameters[1].Direction = ParameterDirection.Input;
            parameters[2].Direction = ParameterDirection.Input;
            parameters[3].Direction = ParameterDirection.Input;
            parameters[4].Direction = ParameterDirection.Input;
            parameters[5].Direction = ParameterDirection.Input;
            parameters[6].Direction = ParameterDirection.Input;
            parameters[7].Direction = ParameterDirection.Input;
            parameters[8].Direction = ParameterDirection.Input;
            parameters[9].Direction = ParameterDirection.Input;
            parameters[10].Direction = ParameterDirection.Input;
            parameters[11].Direction = ParameterDirection.Input;

            OracleHelper.RunProcedure("INSERT_ROOM_EQUIPMENTLAYOUT", parameters);
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(Model.Room.ROOM_EQUIPMENTLAYOUT model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update ROOM_EQUIPMENTLAYOUT set ");
            strSql.Append("LOGICEQUIPMENTNAME=:LOGICEQUIPMENTNAME,");
            strSql.Append("EQUIPMENTPROPERTY=:EQUIPMENTPROPERTY,");
            strSql.Append("TOP=:TOP,");
            strSql.Append("LEFT=:LEFT,");
            strSql.Append("REMARK=:REMARK,");
            strSql.Append("TXTCONTENT=:TXTCONTENT,");
            strSql.Append("TXTPROPERTY=:TXTPROPERTY,");
            strSql.Append("TYPE=:TYPE");
            strSql.Append(" where LOGICEQUIPMENTID=:LOGICEQUIPMENTID ");
            OracleParameter[] parameters = {
					new OracleParameter(":LOGICEQUIPMENTID", OracleType.VarChar,25),
					new OracleParameter(":LOGICEQUIPMENTNAME", OracleType.VarChar,100),
					new OracleParameter(":EQUIPMENTPROPERTY", OracleType.VarChar,1000),
					new OracleParameter(":TOP", OracleType.Number,4),
					new OracleParameter(":LEFT", OracleType.Number,4),
					new OracleParameter(":REMARK", OracleType.VarChar,500),
					new OracleParameter(":TXTCONTENT", OracleType.VarChar,25),
					new OracleParameter(":TXTPROPERTY", OracleType.VarChar,1000),
					new OracleParameter(":TYPE", OracleType.VarChar,20)};
            parameters[0].Value = model.LOGICEQUIPMENTID;
            parameters[1].Value = model.LOGICEQUIPMENTNAME;
            parameters[2].Value = model.EQUIPMENTPROPERTY;
            parameters[3].Value = model.TOP;
            parameters[4].Value = model.LEFT;
            parameters[5].Value = model.REMARK;
            parameters[6].Value = model.TXTCONTENT;
            parameters[7].Value = model.TXTPROPERTY;
            parameters[8].Value = model.TYPE;

            OracleHelper.ExecuteSql(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(string LOGICEQUIPMENTID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from ROOM_EQUIPMENTLAYOUT ");
            strSql.Append(" where LOGICEQUIPMENTID=:LOGICEQUIPMENTID ");
            OracleParameter[] parameters = {
					new OracleParameter(":LOGICEQUIPMENTID", OracleType.VarChar,50)};
            parameters[0].Value = LOGICEQUIPMENTID;

            OracleHelper.ExecuteSql(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.Room.ROOM_EQUIPMENTLAYOUT GetModel(string LOGICEQUIPMENTID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select LOGICEQUIPMENTID,LOGICEQUIPMENTNAME,EQUIPMENTPROPERTY,TOP,LEFT,REMARK,TXTCONTENT,TXTPROPERTY,TYPE from ROOM_EQUIPMENTLAYOUT ");
            strSql.Append(" where LOGICEQUIPMENTID=:LOGICEQUIPMENTID ");
            OracleParameter[] parameters = {
					new OracleParameter(":LOGICEQUIPMENTID", OracleType.VarChar,50)};
            parameters[0].Value = LOGICEQUIPMENTID;

            Model.Room.ROOM_EQUIPMENTLAYOUT model = new Model.Room.ROOM_EQUIPMENTLAYOUT();
            DataSet ds = OracleHelper.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                model.LOGICEQUIPMENTID = ds.Tables[0].Rows[0]["LOGICEQUIPMENTID"].ToString();
                model.LOGICEQUIPMENTNAME = ds.Tables[0].Rows[0]["LOGICEQUIPMENTNAME"].ToString();
                model.EQUIPMENTPROPERTY = ds.Tables[0].Rows[0]["EQUIPMENTPROPERTY"].ToString();
                if (ds.Tables[0].Rows[0]["TOP"].ToString() != "")
                {
                    model.TOP = int.Parse(ds.Tables[0].Rows[0]["TOP"].ToString());
                }
                if (ds.Tables[0].Rows[0]["LEFT"].ToString() != "")
                {
                    model.LEFT = int.Parse(ds.Tables[0].Rows[0]["LEFT"].ToString());
                }
                model.REMARK = ds.Tables[0].Rows[0]["REMARK"].ToString();
                model.TXTCONTENT = ds.Tables[0].Rows[0]["TXTCONTENT"].ToString();
                model.TXTPROPERTY = ds.Tables[0].Rows[0]["TXTPROPERTY"].ToString();
                model.TYPE = ds.Tables[0].Rows[0]["TYPE"].ToString();
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select LOGICEQUIPMENTID,LOGICEQUIPMENTNAME,EQUIPMENTPROPERTY,TOP,LEFT,REMARK,TXTCONTENT,TXTPROPERTY,TYPE ");
            strSql.Append(" FROM ROOM_EQUIPMENTLAYOUT ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return OracleHelper.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            OracleParameter[] parameters = {
                    new OracleParameter(":tblName", OracleType.VarChar, 255),
                    new OracleParameter(":fldName", OracleType.VarChar, 255),
                    new OracleParameter(":PageSize", OracleType.Number),
                    new OracleParameter(":PageIndex", OracleType.Number),
                    new OracleParameter(":IsReCount", OracleType.Clob),
                    new OracleParameter(":OrderType", OracleType.Clob),
                    new OracleParameter(":strWhere", OracleType.VarChar,1000),
                    };
            parameters[0].Value = "ROOM_EQUIPMENTLAYOUT";
            parameters[1].Value = "ID";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return OracleHelper.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  成员方法
    }
}

